<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import systemDeviceBind from '@/api/system/systemDeviceBind'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()
const props = defineProps(["client", "curDevieInfo", "case_id","isDelete"]);

const numberOperation = (newValue, id, numberName) => {
  systemDeviceBind.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  systemDeviceBind.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  beforeRequest: params => {
    // 指定排序字段为浏览量字段
    params.device_id = props.curDevieInfo.id

  },
  id: 'system_device_bind',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: systemDeviceBind.getList,
  recycleApi: systemDeviceBind.getRecycleList,
  add: {
    show: true,
    api: systemDeviceBind.save,
    auth: ['system:deviceBind:save']
  },
  edit: {
    show: true,
    api: systemDeviceBind.update,
    auth: ['system:deviceBind:update']
  },
  delete: {
    show: true,
    api: systemDeviceBind.deletes,
    auth: ['system:deviceBind:delete'],
    realApi: systemDeviceBind.realDeletes,
    realAuth: ['system:deviceBind:realDeletes']
  },
  recovery: {
    show: true,
    api: systemDeviceBind.recoverys,
    auth: ['system:deviceBind:recovery']
  },
  import: {
    show: true,
    url: 'system/deviceBind/import',
    templateUrl: 'system/deviceBind/downloadTemplate',
    auth: ['system:deviceBind:import']
  },
  export: {
    show: true,
    url: 'system/deviceBind/export',
    auth: ['system:deviceBind:export']
  }
})

const columns = reactive([
  {
    title: "",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入"
    }
  },
  {
    title: "设备名称",
    dataIndex: "device_name",
    formType: "input",
    search: true
  },
  {
    title: "设备编号",
    dataIndex: "device_num",
    formType: "input",
    search: true,
    addDisplay: true,
    editDisplay: true,
    hide: false
  },
  {
    title: "设备类型",
    dataIndex: "device_type",
    formType: "select",
    search: true,
    dict: {
      name: "device_type",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
    }
  },
  {
    title: "设备型号",
    dataIndex: "device_model",
    formType: "input"
  },
  {
    title: "设备ip",
    dataIndex: "device_ip",
    formType: "input"
  },
  {
    title: "用户名",
    dataIndex: "username",
    formType: "input"
  },
  {
    title: "密码",
    dataIndex: "password",
    formType: "input"
  },
  {
    title: "厂家名称",
    dataIndex: "device_factory",
    formType: "input"
  },
  {
    title: "安装地址",
    dataIndex: "device_address",
    formType: "input"
  },
  {
    title: "所属机器人",
    dataIndex: "device_id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    addDefaultValue: props.curDevieInfo.id,
    editDefaultValue: props.curDevieInfo.id,
    hide: true,
    sortable: {
      sortDirections: [
        "ascend",
        "descend"
      ],
      sorter: true
    }
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "所属区域",
    dataIndex: "dept_id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "在线状态",
    dataIndex: "status",
    formType: "input"
  },
  {
    title: "现场照片",
    dataIndex: "now_pic",
    formType: "upload"
  },
  {
    title: "设备照片",
    dataIndex: "device_pic",
    formType: "upload"
  },
  {
    title: "备注信息",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'system:deviceBind' } </script>